package cmd

import (
	"fmt"
	"github.com/spf13/cobra"
	"strings"
)

const (
	storageFuncName = "storage"
	storageCmdDesc  = "一段文本的存储管理 : create|get|delete|update|list"

	storageAdminFuncName = "storage"
	storageAdminCmdDesc  = "一段文本的存储管理 : create|get|delete|update|list"
)

var storageCommand = &cobra.Command{
	Use:   "storage",
	Short: "storage 关于存储数据库的操作",
}

var noteCommand = &cobra.Command{
	Use:   "note",
	Short: "note 笔记操作",
	Long: `note 新增、删除、更新、查看一条笔记
	new|delete|update|get a note`,
}

var content string
var ledger string
var sourcePath string
var noteNewCmd = &cobra.Command{
	Use:   "new",
	Short: "new 新增随笔",
	Long:  "new 新增随笔。随笔笔记存储成功后返回一个key，用于检索该条笔记。",
	Run: func(cmd *cobra.Command, args []string) {
		if len(content) == 0 {
			cmd.Help()
			return
		}
		if strings.Contains(content, "\\r\n") || strings.Contains(content, "\\r\n") {

			fmt.Println("笔记存在特殊字符")
		} else {

			fmt.Println(content)
		}
	},
}
var noteReadCmd = &cobra.Command{
	Use:   "read",
	Short: "read from txt file",
	Long:  "read 从指定的txt文件读取长文本随笔",
}

func init() {
	rootCmd.AddCommand(noteCommand)
	noteCommand.AddCommand(noteNewCmd)
	noteNewCmd.Flags().StringVarP(&content, "content", "c", "随笔", "需要存入的随笔")
	noteNewCmd.MarkFlagRequired("content")
	noteNewCmd.Flags().StringVarP(&ledger, "ledger", "l", "DEFAULT", "指定存储账本，当前仅存储在默认账本DEFAULT ，功能实现中")

	noteCommand.AddCommand(noteReadCmd)
	noteReadCmd.Flags().StringVarP(&sourcePath, "sourcePath", "s", "", "需要存入的随笔txt位置")
}
